package com.tac.controller;

import com.tac.common.result.Result;
import com.tac.pojo.Occupant;
import com.tac.pojo.vo.OccupantVo;
import com.tac.service.OccupantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/occupant")
@Api(tags = "常用入住人")
public class OccupantController  {
    @Autowired
    private OccupantService occupantService;


//    /**
//     * 查看用户的常用入住人名字
//     * @param uid
//     * @return
//     */
//    @GetMapping
//    public Result<List<String>> selectName(Long uid){
//        return occupantService.selectName(uid);
//    }
    /**
     * 查看用户的常用入住人和数量
     * @param uid
     * @return
     */
    @GetMapping
    @ApiOperation("查看用户的常用入住人和数量")
    public Result<OccupantVo> selectAll( Long uid){
        return occupantService.selectAll(uid);
    }
    /**
     * 添加常用入住人
     * @param occupant
     * @param uid
     * @return
     */
    @ResponseStatus(HttpStatus.CREATED)
    @PostMapping
    @ApiOperation("添加常用入住人")
    public Result inserte(@RequestBody Occupant occupant, Long uid){
        return occupantService.inserte(occupant,uid);
    }

    /**
     * 删除常用入住人
     * @param id
     * @return
     */
    @DeleteMapping
    @ApiOperation("删除常用入住人")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public Result removeByOccupant(Long id){
        return occupantService.removeByOccupant(id);
    }

    /**
     * 更新常用入住人
     * @param occupant
     * @return
     */
    @PutMapping
    @ApiOperation("更新常用入住人")
    public Result updateByOccupant(@RequestBody Occupant occupant){

        return occupantService.updateByOccupant(occupant);
    }
}
